//
//  AppDelegate.m
//  GameTesting
//
//  Created by jojojiong on 15/4/14.
//  Copyright (c) 2015年 jojojiong. All rights reserved.
//

#import "AppDelegate.h"
#import <JVFloatingDrawerViewController.h>
#import <JVFloatingDrawerSpringAnimator.h>
#import "GTLeftViewController.h"
#import "GTRightViewController.h"
#import "GTDanjiTableViewController.h"
#import "GTMobileGameViewController.h"
#import "GTNetGameViewController.h"



@interface AppDelegate ()


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
//    JVFloatingDrawerViewController *drawerViewController = [[JVFloatingDrawerViewController alloc] init];
//    
//    drawerViewController.leftViewController = [[GTLeftViewController alloc] init];
//
//    drawerViewController.rightViewController  = [[GTRightViewController alloc] init];
    
//    GTDanjiTableViewController *danjiTableViewController = [[GTDanjiTableViewController alloc] init];
//    
//    UINavigationController *dajiNav = [[UINavigationController alloc] initWithRootViewController:danjiTableViewController];
//    drawerViewController.centerViewController = dajiNav;

//    drawerViewController.backgroundImage = [UIImage imageNamed:@"sky"];
//    drawerViewController.animator = [[JVFloatingDrawerSpringAnimator alloc] init];
//    
//    self.drawerViewController = drawerViewController;
    
    [self configureDrawerViewController];
    self.window.rootViewController = self.drawerViewController;
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {}

- (void)applicationDidEnterBackground:(UIApplication *)application {}

- (void)applicationWillEnterForeground:(UIApplication *)application {}

- (void)applicationDidBecomeActive:(UIApplication *)application {}

- (void)applicationWillTerminate:(UIApplication *)application {}

#pragma mark - Drawer View Controllers

- (JVFloatingDrawerViewController *)drawerViewController {
    if (!_drawerViewController) {
        _drawerViewController = [[JVFloatingDrawerViewController alloc] init];
    }
    
    return _drawerViewController;
}

#pragma mark Sides

- (UITableViewController *)leftDrawerViewController {
    if (!_leftDrawerViewController) {
        _leftDrawerViewController = [[GTLeftViewController alloc] init];
    }
    
    return _leftDrawerViewController;
}

- (UITableViewController *)rightDrawerViewController {
    if (!_rightDrawerViewController) {
        _rightDrawerViewController = [[GTRightViewController alloc] init];;
    }
    
    return _rightDrawerViewController;
}

#pragma mark Center

//- (UIViewController *)danjiViewController {
//    if (!_danjiViewController) {
//        _danjiViewController = [[GTDanjiTableViewController alloc] init];
//
//    }
//    
//    return _danjiViewController;
//}

- (UIViewController *)danjiViewController {
    if (!_danjiViewController) {
        _danjiViewController = [[GTDanjiTableViewController alloc] init];

    }
    UINavigationController *Nav = [[UINavigationController alloc] initWithRootViewController:_danjiViewController];
    
    return Nav;
}



- (UIViewController *)mobileViewController {
    if (!_mobileViewController) {
        _mobileViewController = [[GTMobileGameViewController alloc] init];
    }
    UINavigationController *Nav = [[UINavigationController alloc] initWithRootViewController:_mobileViewController];
    
    return Nav;
}

- (UIViewController *)netGameViewController{
    if (!_netGameViewController) {
        _netGameViewController = [[GTNetGameViewController alloc] init];
    }
    
    UINavigationController *Nav = [[UINavigationController alloc] initWithRootViewController:_netGameViewController];
    
    return Nav;
}

- (JVFloatingDrawerSpringAnimator *)drawerAnimator {
    if (!_drawerAnimator) {
        _drawerAnimator = [[JVFloatingDrawerSpringAnimator alloc] init];
    }
    
    return _drawerAnimator;
}


- (void)configureDrawerViewController {
    self.drawerViewController.leftViewController = self.leftDrawerViewController;
    self.drawerViewController.rightViewController = self.rightDrawerViewController;
    self.drawerViewController.centerViewController =  self.danjiViewController ;
    
    
    self.drawerViewController.animator = self.drawerAnimator;
    
    self.drawerViewController.backgroundImage = [UIImage imageNamed:@"sky"];
}

+ (UINavigationController *)centerViewController:(UITableViewController *)tmpCenterViewController
{
    UINavigationController *Nav = [[UINavigationController alloc] initWithRootViewController:tmpCenterViewController];
    return Nav;
}

#pragma mark - Global Access Helper

+ (AppDelegate *)globalDelegate {
    return (AppDelegate *)[UIApplication sharedApplication].delegate;
}

- (void)toggleLeftDrawer:(id)sender animated:(BOOL)animated {
    [self.drawerViewController toggleDrawerWithSide:JVFloatingDrawerSideLeft animated:animated completion:nil];
}

- (void)toggleRightDrawer:(id)sender animated:(BOOL)animated {
    [self.drawerViewController toggleDrawerWithSide:JVFloatingDrawerSideRight animated:animated completion:nil];
}


@end
